<?php
/**
 * Created by Silent Night.
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/9/28
 * Time: 9:19
 */

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;

class Feedback extends Controller{
    private $_model;
    private $title_field = [
       
    ];
    
    public $pagesize=10;
    
    public function _initialize(){
        $this->_model = new \app\admin\model\Feedback();
        $this->assign('LoginUserInfo', $this->LoginUserInfo);
       
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }
    /**
     * 列表页
     * @return mixed
     */
    public function index(){
       
            return $this->fetch('index');
    }

    
  
    public function lists()
    {
  
        $usermodel = new \app\admin\model\User();
        $UserList=$usermodel->getDataForWheres(array('group'=>array('elt',3)));
        $kuid=$_REQUEST['kuid'];
        $where=array();
        if($kuid)
        {
            $where['uid']=$kuid;
        }
        $lists= $this->_model->lists($where,$this->pagesize);
        
        $lists['data']=changeUidToUserinfoForLists($lists['data'],'uid');
        $this->assign('lists', $lists);
        $this->assign('UserList', $UserList);
        
        $this->assign('request', input("request."));
        return view('lists');

    }

    public function tg()
    {
        $uid=$this->LoginUserInfo['UserInfo']['id'];
        $CurrUrl = $_SERVER['HTTP_HOST'];
        $CurrUrl="http://".$CurrUrl."/front/code/web1/index.php?gid=".$uid;
        $this->assign('url', $CurrUrl);
   
        return view('tg');
    }
    public function myzx()
    {
        $this->_model->updateDataForWhere(array('is_read'=>1),array('is_read'=>0));
//         $uid=$this->LoginUserInfo['UserInfo']['id'];
        $lists= $this->_model->lists(array(),$this->pagesize);
    
//         $lists['data']=changeUidToUserinfoForLists($lists['data'],'uid');
        $this->assign('lists', $lists);
    
        $this->assign('request', input("request."));
        return view('myzx');
    
    }
    

    public function reply(){
        $time = time();
        $sys_opt =trim(input("request.sys_opt"));//auth
        $pid =trim(input("request.pid"));//auth
        if ($sys_opt) {
            $conts =trim(input("request.conts"));//auth
            if(empty($conts))
            {
    
                $return = ['err'=>3,'msg'=>'对不起回复内容不能为空'];
                return json($return);
            }
    
            $uid=$this->LoginUserInfo['UserInfo']['id'];
            $name=$this->LoginUserInfo['UserInfo']['nickname'];
            $phone=$this->LoginUserInfo['UserInfo']['phone'];
    
            $insertData=array(
                'uid'=>$uid,
                'name'=>$name,
                'tel'=>$phone,
                'conts'=>$conts,
                'pid'=>$pid,
                 
                'ctime'=>date("Y-m-d H:i:s"),
            );
            $MODEL = new \app\admin\model\Reply();
            $res = $MODEL->add($insertData);
             
            if($res){
               
                $return = ['err'=>0,'msg'=>'操作成功'];
                return json($return);
            }else{
                $return = ['err'=>3,'msg'=>'操作失败'];
                return json($return);
            }
        }
    
    
        
        
        $replyModel = new \app\admin\model\Reply();
   
       
        $lists= $replyModel->lists(array('pid'=>$pid),$this->pagesize);
        
       
        $this->assign('lists', $lists);
       
        //设置全局信息
        $title="回复";
        $this->assign('title', $title);
        $this->assign('pid', $pid);
    
        return view('reply');
    
    }
   
    /**
     * 删除
     * 支持批量删除和单条删除
     * @return mixed
     */
    public function delData(){
        $return=[];
        $id =trim(input("request.id"));//auth
        if(empty($id))
        {
            $return = ['err'=>1,'msg'=>'操作失败'];
            return json($return);
        }
        
        $userInfo =$this->_model->getID($id);
        $res=$this->_model->delData(array('id'=>$id));
        
        if($res){
            
           
            $return = ['err'=>0,'msg'=>'操作成功'];
            return json($return);
        }else{
            $return = ['err'=>3,'msg'=>'操作失败'];
            return json($return);
        }
        
       
    }
    
    
    
    public function delReplyData(){
        $return=[];
        $id =trim(input("request.id"));//auth
        if(empty($id))
        {
            $return = ['err'=>1,'msg'=>'操作失败'];
            return json($return);
        }
        $MODEL = new \app\admin\model\Reply();
       
        $res=$MODEL->delData(array('id'=>$id));
    
        if($res){
    
             
            $return = ['err'=>0,'msg'=>'操作成功'];
            return json($return);
        }else{
            $return = ['err'=>3,'msg'=>'操作失败'];
            return json($return);
        }
    
         
    }
    
  
    public function dealData(){
        $return=[];
        $id =trim(input("request.id"));//auth
        if(empty($id))
        {
            $return = ['err'=>1,'msg'=>'操作失败'];
            return json($return);
        }
    
        $w=array(
            'id'=>$id
        );
        $update=array(
            'stats'=>1,
            'dealtime'=>date("Y-m-d H:i:s"),
        );
        $res = $this->_model->updateDataForWhere($update,$w);
         
        
        if($res){
    
             
            $return = ['err'=>0,'msg'=>'操作成功'];
            return json($return);
        }else{
            $return = ['err'=>3,'msg'=>'操作失败'];
            return json($return);
        }
    
         
    }
    

    public function infoData(){
    
         
        $id =trim(input("request.id"));//auth

        $info= $this->_model->getDataForWhere(array('id'=>$id));
        $info['UserInfo']=getUserInfoForID($info['uid'],'*');
        $this->assign('info', $info);
    
      
        $title="详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('infoData');
    
    }
    

    public function myinfoData(){
    
         
        $id =trim(input("request.id"));//auth
    
        $info= $this->_model->getDataForWhere(array('id'=>$id));
        $info['UserInfo']=getUserInfoForID($info['uid'],'*');
        $this->assign('info', $info);
    
    
        $title="详情";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('myinfoData');
    
    }
    
}